package com.wxq.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Queue;


@RestController
public class ProviderController {
    //注入存放消息的队列
    @Autowired
    private Queue queue;

    //注入springboot封装的工具类
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @RequestMapping("send")
    public void send(String name) {
        //方法1 添加消息到消息队列
        jmsMessagingTemplate.convertAndSend(queue, name);
        //方法2 不需要手动创建queue，系统会直接创建名为test的队列
        //jmsMessagingTemplate.convertAndSend("test",name);
    }

}
